<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>07-动态路由匹配</title>
</head>
<body>
  <div id="app">
    <h1>Hello VueRouter!</h1>
    <p>
      <router-link to='/uesr/bar'>bar用户</router-link>
      <router-link to='/user/foo'>foo用户</router-link>
    </p>
    <!-- 路由出口 -->
    <router-link></router-link>
  </div>
</body>
<!-- 引入vue -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 引入VueRouter -->
<script src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script>
  const User = {
    template:`<div>
        <h1>这里是User组件 {{ $route.parmas.id }}</h1>
      </div>`,
      // 响应路由参数变化,方法一用wath监听
      // watch:{
      //   $route(newVal,oldVal){
      //     console.log(newVal);
      //     console.log(oldVal);
      //   }
      // }
      // 响应路由参数变化,通过导航守卫
      beforeRouteUpdate(to,form,next){
        console.log(to);
        console.log(from);
        next()
      }
  }

  var routes = [
    {path:'/user/:id',component: User},
  ];
  var router =new VueRouter({
    routes
  });
  var app = new Vue({
    el:"#app",
    router
  })
</script>
</html>